﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper {
	public class ProfitDayMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public ProfitDayMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<ProfitDay, profit_day_dto>()
				.ForMember(dest => dest.pay_channel, src => src.MapFrom(c => c.PayChannel))
				.ForMember(dest => dest.pay_amount, src => src.MapFrom(c => c.PayAmount))
				.ForMember(dest => dest.off_amount, src => src.MapFrom(c => c.OffAmount))
				.ForMember(dest => dest.create_date, src => src.MapFrom(c => c.CreateDate.ToDateTime()))
				.ForMember(dest => dest.fee_cost, src => src.MapFrom(c => c.FeeCost))
				.ForMember(dest => dest.settle_cost, src => src.MapFrom(c => c.SettleCost))
				.ForMember(dest => dest.merchant_profit, src => src.MapFrom(c => c.MerchantProfit))
				.ForMember(dest => dest.pay_count, src => src.MapFrom(c => c.PayCount))
				.ForMember(dest => dest.day_profit, src => src.MapFrom(c => c.DayProfit));

			_cfg.CreateMap<profit_day_dto, ProfitDay>()
				.ForMember(dest => dest.PayChannel, src => src.MapFrom(c => c.pay_channel))
				.ForMember(dest => dest.PayAmount, src => src.MapFrom(c => c.pay_amount))
				.ForMember(dest => dest.OffAmount, src => src.MapFrom(c => c.off_amount))
				.ForMember(dest => dest.CreateDate, src => src.MapFrom(c => c.create_date.ToUnix()))
				.ForMember(dest => dest.FeeCost, src => src.MapFrom(c => c.fee_cost))
				.ForMember(dest => dest.SettleCost, src => src.MapFrom(c => c.settle_cost))
				.ForMember(dest => dest.MerchantProfit, src => src.MapFrom(c => c.merchant_profit))
				.ForMember(dest => dest.PayCount, src => src.MapFrom(c => c.pay_count))
				.ForMember(dest => dest.DayProfit, src => src.MapFrom(c => c.day_profit));
		}
	}
}